<template>
  <div style="display:inline-block;">
    <div class="mui-numbox" style="width: 140px;height: 34px;" data-numbox-min='1' :data-numbox-max='max'>
      <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
      <input ref="numbox" class="mui-input-numbox" type="number" value="1" @change="countChanged"/>
      <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
    </div>
  </div>
</template>

<script>
  import mui from '../../lib/mui/js/mui.min';

  export default {
    mounted() {
      //初始化数字选择框组件
      mui('.mui-numbox').numbox();
    },
    methods: {
      countChanged() {
        //每当数量修改时，立即调用父组件的方法将数据传递给父组件
        this.$emit('getcount', parseInt(this.$refs.numbox.value));
      }
    },
    props: ['max'],
    watch: {
      'max': function (newVal, oldVal) {
        mui('.mui-numbox').numbox().setOption('max', newVal);
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>